<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@taglib
	uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

	<sql:query dataSource="jdbc/sharewithme" var="rs">
select sum(tbshare.sharevalue) as sumvalue,
countrate ,  ROUND ( sum(tbshare.sharevalue) / countrate, 1 ) as ratepoint
from sharewithme.tbshare tbshare, ShareWithMe.TBTopView tbtopview
where sharegroupid = 5 and sharetypeid = 3 
and tbtopview.isbn = '${param.bisbn }'
</sql:query>

	<c:forEach items="${rs.rows }" var="rate">${rate.ratepoint }</c:forEach>
	: ${sessionScope.User.userId } 
	<%-- **** give book's rate --%>
	<sql:query var="rs" dataSource="jdbc/sharewithme">
		<%-- **** check for userid, cannot vote twice --%>
select count(*) as userid from sharewithme.tbshare
where sharegroupid = 5 
and sharetypeid = 3
and isbn = '${param.isbn }'
and userid = '${sessionScope.User.userId }'
</sql:query>
	<c:forEach items="${rs.rows }" var="user">
		${user.userid == 0 } : ${sessionScope.User.userId != null}
		<c:choose>
			<c:when test="${(user.userid == 0) && (sessionScope.User.userId != null)} ">
				<%-- **** check for userid, cannot vote twice --%>

				<select name="ratePoint">
					<c:forEach begin="1" end="5" step="1" var="rate">
						<option value="${rate }">${rate }</option>
					</c:forEach>
				</select>
				<input type="submit" value="Vote!" name="voteButton">
<%-- 
				<c:if test="${param.voteButton != null }">--%>
					<%-- *** tbshare vote 
					<sql:update var="rs" dataSource="jdbc/sharewithme">
				INSERT INTO `sharewithme`.`tbshare` 
				(`ShareGroupID`, `ShareTypeID`, `ShareValue`, `UserID`, `ISBN`) 
				VALUES ('5', 3, ${param.ratePoint }, '${sessionScope.User.getUserId() }', '${param.isbn }');
				</sql:update>--%>

					<%-- *** increase vote 
					<sql:update var="rs" dataSource="jdbc/sharewithme">
				 UPDATE ShareWithMe.TBTopView 
				 SET countrate= countrate +'1'
				 where ISBN = '${param.isbn }';
				</sql:update>
				</c:if> --%>
			</c:when>
		</c:choose>
	</c:forEach>
	 
